<template>
  <Card>
    <div class="card">
      <img src="../assets/image/th.png" class="icon" alt="" />
      <div class="userinfo">
        <div class="line">
          登录账号:
          <div class="login">{{ userInfo.nickName }}</div>
        </div>
        <div class="line">
          注册时间:
          <div class="login">{{ userInfo.gmtCreate }}</div>
        </div>
        <div class="line">
          手机号:
          <div class="login">{{ userInfo.phone }}</div>
        </div>
        <div class="img line">
          三方账号绑定:
          <div v-show="result.flag">
            <img src="../assets/image/微信.png" class="wechat" alt="" />
            <div class="getbind" @click="change">修改</div>
          </div>
          <div v-show="!result.flag">
            <div class="getbind" @click="add">添加</div>
          </div>
        </div>
      </div>
    </div>

    <el-dialog title="第三方账号绑定" :visible.sync="show1" append-to-body :before-close="guan">
      <div class="main">
        <div class="weibang">
          <img src="../assets/image/微信.png" class="bigwechat" alt="" />
          <div class="wx">
               <div class="wexname">微信<span style="margin-left:10px">{{result.flag?'已绑定':'未绑定'}}</span></div>
          <div class="nickname">{{result.nickName}}</div>
          </div>
         
        </div>
        <div>
          <el-button type="success" v-show="!result.flag" @click="getqrcode"
            >立即绑定</el-button
          >
          <el-popover placement="top" width="160" v-model="visible">
            <p>确定解除绑定?</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="visible = false"
                >取消</el-button
              >
              <el-button type="primary" size="mini" @click="primary"
                >确定</el-button
              >
            </div>
            <el-button slot="reference" v-show="result.flag"
              >解除绑定</el-button
            >
          </el-popover>
        </div>
      </div>

      <el-dialog
        width="30%"
        title="绑定第三方"
        :visible.sync="show2"
        append-to-body
        center
      >
      <div class="qrcode">
      <img :src=" qrcode" class="codeImg" />
      <div>微信扫描二维码绑定第三方,绑定成功之后请刷新页面</div>
      
      </div>
      </el-dialog>
      <!-- <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="show1 = false">确定</el-button>
      </div> -->
    </el-dialog>
  </Card>
</template>

<script>

export default {
  data() {
    return {
      userInfo: {},
      result: "",
      show1: false,
      show2: false,
      show3: false,
      visible: false,
      qrcode: "",
    };
  },
  created() {
    this.$http("/stage/user/getUserBasicInfo", {}, "get", (res) => {
      if (res.data.code == 200) {
        this.userInfo = res.data.data;
        console.log(this.userInfo);
        console.log(this.userInfo.gmtCreate);
      } else {
        this.$Message.error(res.data.msg);
      }
    });
    this.getBindWeChatResult();
  },
  methods: {
      guan(){
          this.show1=false
          this.getBindWeChatResult()
      },
    getBindWeChatResult() {
      this.$http("/stage/user/getBindWeChatResult", {}, "get", (res) => {
        if (res.data.code == 200) {
          this.result = res.data.data;
        } else {
          this.$Message.error(res.data.msg);
        }
      });
    },
    change() {
      this.show1 = true;
    },
    add() {
      this.show1 = true;
    },
    primary() {
      this.$http("/stage/user/unbindLoginWeChat", {}, "get", (res) => {
        if (res.data.code == 200) {
          this.$Message.success("解绑成功");
          this.getBindWeChatResult();
        } else {
          this.$Message.error(res.data.msg);
        }
      });
      this.visible = false;
      this.show1 = false;
    },
    getqrcode() {
      this.$http("/stage/user/getBindLoginWeChatQrCode", {}, "get", (res) => {
        if (res.data.code == 200) {
            this.show2=true
          this.qrcode = res.data.data;
        } else {
          this.$Message.error(res.data.msg);
        }
      });
    },
  },
};
</script>

<style scoped>
.card {
  display: flex;
  align-items: center;
}
.icon {
  width: 80px;
  height: 80px;
  border-radius: 40px;
  margin-left: 70px;
}
.userinfo {
  color: #999;
  display: flex;
  flex-wrap: wrap;
  padding: 50px;
  width: 70%;
}
.userinfo div {
  display: flex;
  width: 40%;
}
.line {
  padding: 20px 0 20px 0;
}
.userinfo div .login {
  color: black;
  margin-left: 40px;
}
.wechat {
  width: 20px;
  height: 20px;
  margin-left: 40px;
  margin-right: 20px;
}
.getbind {
  color: blue;
  cursor: pointer;
}
.bigwechat {
  width: 70px;
  height: 70px;
  margin-right: 30px;
}
.jiechubang {
  border: 1px solid #999;
  color: #999;
  padding: 10px 40px;
  display: inline-block;
}
.lijibang {
  border: 1px solid #19be6b;
  background: #19be6b;
  color: #fff;
  padding: 10px 40px;
  display: inline-block;
}
.main {
  display: flex;
  width: 80%;
  margin-left: 10%;
  justify-content: space-between;
  align-items: center;
}
.weibang {
  display: flex;
}
.qrcode{
    width: 100%;
    height: 100%;
  text-align: center;
  font-size: 18px;
}
.wx{
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    
}
.nickname{

}
</style>